$(function () {
    //时间组件
    jeDate("#indate", {
        format: "YYYY年MM月DD日",
        isTime: false,
        minDate: "2014-09-19 00:00:00",
        zIndex:'99999999'
    });
    //文字编辑器组件
    var E = window.wangEditor
    var editor2 = new E('#text')
    editor2.create();
    // 图片预览功能
    $("#inputCover").change(function () {
        let file = this.files[0];
        let url = URL.createObjectURL(file);
        $(this).prev('img').attr('src', url);
    });
    //文章分类初始化渲染
    $.ajax({
        url: BigNew.category_list,
        success(backData) {
            let Html = template('categoryId', backData);
            $('[name=categoryId]').html(Html);
        }
    });
    //文章内容提交回调函数
    function articleEdit(state) {
        let data = new FormData($('#form')[0]);
        data.append('state', state);
        // data.append('content', editor2.txt.html());
        $.ajax({
            type: 'post',
            url: BigNew.article_publish,
            data,
            processData: false,
            contentType:false,
            success(backData) {
                if (backData.code == 200) {
                    alert(backData.msg);
                    window.location.href = './article_list.html';
                }
            },
            error(xhr, state, err) {
                alert(xhr.responseJSON.msg)
                // console.log(xhr);
            }
        })
    };
    $('.btn-release').click(function (e) {
        e.preventDefault();
        articleEdit('已发布');
    });
    $('#form .btn-draft').click(function (e) {
        e.preventDefault();
        articleEdit('');
       
    })

})